Report with geocomputation examples for point, line and polygon data

This document provides the methodlogy and the main results regarding the spatialization of pollutation inventory.

# Function for preparing point data for spatialization 
# Parameters:
#  - source.list - list with source data and total inventory
#  - distribute - TRUE or FALSE, depend on that if you want to distribute total inventory emissions to sources, when difference exists
corsum2sf <- function(source.list, distribute = FALSE){
  source.list$sources$points[, vars] <- source.list$sources$points[, vars] %>% dplyr::mutate_all(~replace(., is.na(.), 0))
  source.list[[2]][[2]][, vars] <- source.list[[2]][[2]][, vars] %>% dplyr::mutate_all(~replace(., is.na(.), 0))
  
  points.sum <- source.list$sources$points %>% 
    dplyr::select(., vars) %>% 
    apply(., 2, sum) %>% 
    t(.) %>% 
    as.data.frame() %>%
    dplyr::mutate_if(is.numeric, round, 2)
  
  points.total <- source.list[[2]][[2]][, vars] %>% 
    dplyr::mutate_if(is.numeric, round, 2) %>%
    as.data.frame()
  
  if(!identical(points.sum, points.total) & distribute == TRUE){
    d <- (points.total - points.sum)[1, ]
    zero.ind <- source.list$sources$points[, vars] == 0
    w <- replace(source.list$sources$points[, vars], zero.ind, 1) %>% 
      apply(., 2, function(x) x/sum(x)) %>%
      as.data.frame() %>%
      dplyr::mutate_all(~replace(., is.na(.), 0))
    
    cor.data <- as.matrix(w) %*% diag(d) + source.list$sources$points[, vars]
    source.list$sources$points[, vars] <- cor.data
    source.sf <- st_as_sf(x = source.list$sources$points, coords = c("Longitude", "Latitude"),  crs = "+proj=longlat +datum=WGS84")
  }else{
    source.sf <- st_as_sf(x = source.list$sources$points, coords = c("Longitude", "Latitude"),  crs = "+proj=longlat +datum=WGS84")
  }
  return(source.sf)
}
# Function for preparing polygon data for spatialization 
# Parameters:
#  - source.list - list with source data and total inventory
#  - distribute - TRUE or FALSE, depend on that if you want to distribute total inventory emissions to sources, when difference exists

corsum2sf_polygon <- function(source.list, distribute = FALSE){
  source.list$sources$polygon[, vars] <- source.list$sources$polygon[, vars] %>% dplyr::mutate_all(~replace(., is.na(.), 0)) %>% st_drop_geometry()
  source.list[[2]][[2]][, vars] <- source.list[[2]][[2]][, vars] %>% dplyr::mutate_all(~replace(., is.na(.), 0))
  
  polygon.sum <- source.list$sources$polygon %>% 
    st_drop_geometry() %>%
    dplyr::select(., vars) %>% 
    apply(., 2, sum) %>% 
    t(.) %>% 
    as.data.frame() %>%
    dplyr::mutate_if(is.numeric, round, 2)
  
  polygon.total <- source.list[[2]][[2]][, vars] %>% 
    dplyr::mutate_if(is.numeric, round, 2) %>%
    as.data.frame()
  
  if(!identical(polygon.sum, polygon.total) & distribute == TRUE){
    d <- (polygon.total - polygon.sum)[1, ]
    zero.ind <- source.list$sources$polygon[, vars] %>% st_drop_geometry() == 0
    w <- replace(source.list$sources$polygon[, vars] %>% st_drop_geometry(), zero.ind, 1) %>% 
      apply(., 2, function(x) x/sum(x)) %>%
      as.data.frame() %>%
      dplyr::mutate_all(~replace(., is.na(.), 0))
    
    cor.data <- as.matrix(w) %*% diag(d) + source.list$sources$polygon[, vars]%>% st_drop_geometry()
    source.list$sources$polygon[, vars] <- cor.data
    source.sf <- source.list$sources$polygon
  }else{
    source.sf <- source.list$sources$polygon
  }
  return(source.sf)
}

Example - point data

## New names:
## * `` -> ...10
## OGR data source with driver: ESRI Shapefile 
## Source: "D:\R_projects\Spatialization\Grid\Polygons_5km_UTM_34N.shp", layer: "Polygons_5km_UTM_34N"
## with 3124 features
## It has 1 fields
## Integer64 fields read as strings:  ID

1A1a - Public heat and electricity production

Example - line data

## OGR data source with driver: ESRI Shapefile 
## Source: "D:\R_projects\Spatialization\Grid\Polygons_5km_UTM_34N.shp", layer: "Polygons_5km_UTM_34N"
## with 3124 features
## It has 1 fields
## Integer64 fields read as strings:  ID

1A3c-Railways

## OGR data source with driver: ESRI Shapefile 
## Source: "D:\R_projects\Spatialization\Data\pruge\Pruge_osm_32634.shp", layer: "Pruge_osm_32634"
## with 4921 features
## It has 4 fields

Example - polygon data

## OGR data source with driver: ESRI Shapefile 
## Source: "D:\R_projects\Spatialization\Grid\Polygons_5km_UTM_34N.shp", layer: "Polygons_5km_UTM_34N"
## with 3124 features
## It has 1 fields
## Integer64 fields read as strings:  ID

1A4ai - Commercial/Institutional: Stationary Combustion

## OGR data source with driver: ESRI Shapefile 
## Source: "D:\R_projects\Spatialization\Data\clc\CLC18_RS.shp", layer: "CLC18_RS"
## with 34794 features
## It has 6 fields
## [1] "LC_COLLATE=Serbian (Latin)_Bosnia and Herzegovina.1250;LC_CTYPE=Serbian (Latin)_Bosnia and Herzegovina.1250;LC_MONETARY=Serbian (Latin)_Bosnia and Herzegovina.1250;LC_NUMERIC=C;LC_TIME=Serbian (Latin)_Bosnia and Herzegovina.1250"
## OGR data source with driver: ESRI Shapefile 
## Source: "D:\R_projects\Spatialization\Data\opstine\gadm36_SRB_2.shp", layer: "gadm36_SRB_2"
## with 161 features
## It has 13 fields